#! /system/bin/sh
burp_dir=/data/local/tmp/burp # FIXME: should eventually be replaced with actual install directory
export OPENSSL_CONF="${burp_dir}/openssl.conf"
tmpconf="${burp_dir}/CA-client/tmp.conf"
keypath="$3"
requestpath="$6"
name="$8"

echo "generating key ${name}: ${keypath}"
${burp_dir}/openssl genrsa -out "${keypath}" 2048

echo 'RANDFILE = /dev/urandom' > "${tmpconf}"
echo '[ req ]' >> "${tmpconf}"
echo 'distinguished_name = req_distinguished_name' >> "${tmpconf}"
echo 'prompt = no' >> "${tmpconf}"
echo '[ v3_req ]' >> "${tmpconf}"
echo 'basicConstraints=CA:false' >> "${tmpconf}"
echo '[ req_distinguished_name ]' >> "${tmpconf}"
echo 'commonName = '"${name}" >> "${tmpconf}"

echo "generating certificate signing request: ${requestpath}"
${burp_dir}/openssl req -config "${tmpconf}" -new -key "${keypath}" -out "${requestpath}" -extensions v3_req
rm "${tmpconf}"
